package cn.com.victorysoft;

import cn.com.victorysoft.oadd.util.PageBean;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

public class BaseAction extends ActionSupport {

    private Map params = new HashMap();//页面参数

    private PageBean pageBean = new PageBean();//分页的javaBean

    public PageBean getPageBean() {
        return pageBean;
    }

    public void setPageBean(PageBean pageBean) {
        this.pageBean = pageBean;
    }

    public Map getParams() {
        return params;
    }

    public String[] getParam(String key) {
        return (String[]) params.get(key);
    }

    public String getFirstParam(String key) {
        String[] strs = getParam(key);
        return strs == null ? "" : strs[0];
    }

    public void setParams(Map params) {
        this.params = params;
    }
    /**
     * 返回结果信息
     *
     * @param info
     */
    protected void backInfo(String info) {
        try {
            HttpServletResponse response = ServletActionContext.getResponse();
            response.setContentType("text/html charset=utf-8");
            response.setCharacterEncoding("UTF-8");
            response.setHeader("pragma", "no-cache");
            response.setHeader("cache-control", "no-cache");
            PrintWriter out = response.getWriter();

            out.print(info);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}